import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


public class NHPH2{
	
	
	public static void main(String args[]) {
		int[] nhph = NHPF();
		System.out.println("");
	}
	public static int[] NHPF()
	{
		
		ArrayList<HashMap<String, Number>> Priority1 = new ArrayList<HashMap<String, Number>>();
		ArrayList<HashMap<String, Number>> Priority2 = new ArrayList<HashMap<String, Number>>();
		ArrayList<HashMap<String, Number>> Priority3 = new ArrayList<HashMap<String, Number>>();
		ArrayList<HashMap<String, Number>> Priority4 = new ArrayList<HashMap<String, Number>>();
		
		List<HashMap<String, Number>> processList = processGenerator();
		printList(processList);
		int totalProcess = processList.size();
		int[] result = new int[102];
		int time = 0;
		
		for (int k=0; k<processList.size() ; k++){
		int Priority = processList.get(k).get("priority").intValue();
	    int  Rtime = processList.get(k).get("runTime").intValue();
	
		if (Priority==1){
			Priority1.add(processList.get(k));}
		if (Priority==2){
			Priority2.add(processList.get(k));}
		if (Priority==3){
			Priority3.add(processList.get(k));}
		if (Priority==4){
			Priority4.add(processList.get(k));}}
		
		
		for (int i=0;i<Priority1.size();i++)
		{     
		      int runT = Priority1.get(i).get("runTime").intValue();
		      for(int j=0;j<runT;j++) {
		    	  System.out.print("time: "+time+"\t");
		    	  System.out.print("pid:"+Priority1.get(i).get("pid").intValue()+"\t\n");
		    	  result[time++] = Priority1.get(i).get("pid").intValue();
		      }
		  
	    }
		for (int i=0;i<Priority2.size();i++)
		{
			  int runT = Priority2.get(i).get("runTime").intValue();
			  for(int j=0;j<runT;j++){
			  System.out.print("time: "+time+"\t");
	          System.out.print("pid:"+Priority2.get(i).get("pid").intValue()+"\t\n");
	          result[time++] = Priority2.get(i).get("pid").intValue();}
	    }
		for (int i=0;i<Priority3.size();i++)
		{
			  int runT = Priority3.get(i).get("runTime").intValue();
			  for(int j=0;j<runT;j++){
			  System.out.print("time: "+time+"\t");
	          System.out.print("pid:"+Priority3.get(i).get("pid").intValue()+"\t\n");
	          result[time++] = Priority3.get(i).get("pid").intValue();}
			  
	    }
		for (int i=0;i<Priority4.size();i++)
		{
			  int runT = Priority4.get(i).get("runTime").intValue();
			  for(int j=0;j<runT;j++){
		      System.out.print("time: "+time+"\t");
	          System.out.print("pid:"+Priority4.get(i).get("pid").intValue()+"\t\n");
	          result[time++] = Priority4.get(i).get("pid").intValue();}
	    }
		result[101] = totalProcess;
		return result;
	}
	private static List<HashMap<String, Number>> processGenerator() {
		List<HashMap<String, Number>> processList = new ArrayList<HashMap<String, Number>>();
		int pid = 1;
		while (isFilled(processList)) {
			HashMap<String, Number> p = new HashMap<String, Number>();
			int runTime = (int) (Math.random() * 10) + 1;
			int priority = 1 + (int) (Math.random() * 4);
			if (pid == 1) {
				p.put("arrivalTime", 0);
				p.put("runTime", runTime);
				p.put("pid", pid++);
				p.put("completed", 0);
				p.put("priority", priority);
			} else {
				float previousArrivalTime = processList.get(pid-2).get("arrivalTime").floatValue();
				int previousRunTime = processList.get(pid-2).get("runTime").intValue();
				float arrivalTime = (float) (previousArrivalTime + (Math.random() * (float) previousRunTime));
				p.put("arrivalTime", arrivalTime);
				p.put("runTime", runTime);
				p.put("pid", pid++);
				p.put("completed", 0);
				p.put("priority", priority);
			}
			processList.add(p);
		}
		int runTimeSum = 0;
		for (int i = 0; i < processList.size(); i++) {
			runTimeSum += processList.get(i).get("runTime").intValue();
		}
		int runTime = 100 - runTimeSum + 1;
		int priority = 1 + (int) (Math.random() * 4);
		HashMap<String, Number> p = new HashMap<String, Number>();
		float previousArrivalTime = processList.get(pid-2).get("arrivalTime").floatValue();
		int previousRunTime = processList.get(pid-2).get("runTime").intValue();
		float arrivalTime = (float) (previousArrivalTime + (Math.random() * (float) previousRunTime));
		p.put("arrivalTime", arrivalTime);
		p.put("runTime", runTime);
		p.put("pid", pid);
		p.put("completed", 0);
		p.put("priority", priority);
		processList.add(p);
		return processList;
	}
	
	private static boolean isFilled(List<HashMap<String, Number>> pList) {
		int runTimeSum = 0;
		for (int i = 0; i < pList.size(); i++) {
			runTimeSum += pList.get(i).get("runTime").intValue();
		}
		if (runTimeSum >= 90) return false;
		return true;
	}
	        
	        private static void printList(List<HashMap<String, Number>> pl) {
	    		for (int i = 0; i < pl.size(); i++) {
	    			System.out.print("pid: "+pl.get(i).get("pid")+"\t");
	    			System.out.print("Arrival Time: "+pl.get(i).get("arrivalTime")+"\t");
	    			System.out.print("Run Time: "+pl.get(i).get("runTime")+"\t");
	    			System.out.println("Priority: "+pl.get(i).get("priority"));
	    		}
	    		System.out.println();
	    	}
	}
